﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Types;

namespace Client
{
    public partial class SearchResultQuestionForm : Form
    {
        public delegate void UpdateFileContentDelegate(string fileContent);
        public delegate void UpdateCourseNameDelegate(string courseName);

        public SearchResultQuestionForm(QuestionType question)
        {
            InitializeComponent();
            idTextBox.Text = question.id.ToString();
            summaryRichTextBox.Text = question.summary;
            filePathTextBox.Text = question.filePath;
            dateTextBox.Text = question.date.ToString();
            usernameTextBox.Text = question.creatorName;
            ClientManager.Instance.updateFileContent += new ClientManager.UpdateFileContent(this.UpdateFileContent);
            ClientManager.Instance.updateCourseName += new ClientManager.UpdateCourseName(this.UpdateCourseName);
        }

        private void UpdateFileContent(string fileContent)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateFileContentDelegate(this.UpdateFileContent), fileContent);
            }
            else
            {
                fileContentRichTextBox.Text = fileContent;
            }
        }

        private void UpdateCourseName(string courseName)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateCourseNameDelegate(this.UpdateCourseName), courseName);
            }
            else
            {
                courseTextBox.Text = courseName;
            }
        }
    }
}
